import requests
from pyquery import PyQuery as pq

def extract_info(url):
   headers = {
       'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
   }
   response = requests.get(url, headers=headers)
   html = response.text
   doc = pq(html)

   # 提取分类名称和网址
   categories = []
   for a in doc('div.search-list > a'):
       name = pq(a).text().strip()
       link = pq(a).attr('href')
       categories.append({'name': name, 'link': link})

   print(categories)

# 房天下网站
extract_info('https://bj.fang.com/quanwangso/search.html?city=bj&refer=sy_seach')

# 瓜子二手车网站
extract_info('https://www.guazi.com/bj/buy/')


# 抽不到……